﻿Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client

Public Class ProjectDashboardControl

    Private m_Project As Project

    Public ReadOnly Property Project() As Project
        Get
            Return m_Project
        End Get
    End Property

    Private m_ViewMode As Node.TreeType

    Public ReadOnly Property ViewMode() As Node.TreeType
        Get
            Return m_ViewMode
        End Get
    End Property

    Public Sub SetValues(ByVal Project As Project, ByVal ViewMode As Node.TreeType)
        m_Project = Project
        m_ViewMode = ViewMode
        Refresh()
    End Sub

    Public Sub SetValue(ByVal ViewMode As Node.TreeType)
        m_ViewMode = ViewMode
        Refresh()
    End Sub

    Public Overrides Sub Refresh()
        If Not Project Is Nothing Then
            Me.ux_ProjectDetailsControl.Project = m_Project
            Me.ux_Panel.Controls.Clear()
            '--------------------------------
            Dim Nodes As NodeCollection = Nothing

            Select Case ViewMode
                Case Node.TreeType.Area
                    Nodes = Project.AreaRootNodes
                Case Node.TreeType.Iteration
                    Nodes = Project.IterationRootNodes
            End Select

            Dim TotalWidthInUnits As Integer = 0

            For Each Node As Node In Nodes
                TotalWidthInUnits = TotalWidthInUnits + Node.ComputeWidthInNodes
            Next


            Dim tbl As New TableLayoutPanel
            tbl.BackColor = Color.Lime
            tbl.Dock = DockStyle.Left
            tbl.Width = TotalWidthInUnits * 300 ' TODO Set With
            tbl.ColumnCount = Nodes.Count
            Me.ux_Panel.Controls.Add(tbl)

            For c As Integer = 0 To Nodes.Count - 1
                Dim newNodeItemDisplay As New NodeItemDisplayControl
                newNodeItemDisplay.Dock = DockStyle.Fill
                tbl.Controls.Add(newNodeItemDisplay, c, 0)
                Dim cWidth As Integer = Nodes.Count * 290
                tbl.ColumnStyles.Add(New ColumnStyle(SizeType.Absolute, cWidth))
                newNodeItemDisplay.SetValues(Project, Nodes(c))
            Next

        End If
        MyBase.Refresh()
    End Sub

End Class

